function [Ypred] = kmsplin(data, label, C)
%       Suqi Liu

X = double(data); %size n, both labeled and unlabeled data
Y = double(label); %size l < n, labels
l = size(Y,1);
n = size(X,1);
Xtr = X(1:l,:);
Xts = X(l+1:n,:);

K = Xtr*Xtr';
K = K/max(max(K));
Q = (Y*Y').*K;

cvx_begin sdp
    cvx_solver sedumi
    variable delta(l,1) nonnegative
    variable nu(l,1) nonnegative
    variable t
    
    minimize t
    subject to
        [Q ones(l,1)+nu-delta; (ones(l,1)+nu-delta)' t-2*C*ones(1,l)*delta] >= 0
cvx_end

a = Q\(ones(l,1)+nu-delta);
T = Xts*Xtr';
Ypred = int8(sign(T*(Y.*a)));
end